﻿//-----------------------------------------------------------------------
// <copyright file="AccountController.cs" company="SLWY Enterprises">
// * Copyright (C) 2017 四川商旅无忧科技有限公司 版权所有。
// * version : 1.0
// * author  : qinchaoyue
// * FileName: AccountController.cs
// * history : created by qinchaoyue 2017-10-16 04:24:29
// </copyright>
//-----------------------------------------------------------------------

using System.Collections.Generic;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Slwy.Application.Dtos;
using Slwy.Application.Interfaces;
using Slwy.Core.Entities;
using Slwy.Mvc.Controller;
using Slwy.Utility.Helper;

namespace WebApplication.Controllers
{
    using System.Linq;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;

    using Pivotal.Discovery.Client;

    using Slwy.Data.Entity.Interfaces;
    using Slwy.FrameCore.Helper;
    using Slwy.Utility.Extensions;
    using Slwy.Utility.SlwyException;

    /// <summary>
    /// 帐号操作类
    /// </summary>
    [Route("api/[controller]")]
    public class ExceptionController : SlwyController
    {
        /// <summary>
        /// 测试
        /// 使用扩展方法验证参数是否为空
        /// ,如果为空返回 code = 1, data = 用户自定义, message = "请求成功"
        /// </summary>
        /// <returns></returns>
        [HttpPost("slwyargumentnull")]
        public IActionResult SlwyArgumentNull()
        {
            AccountOutDto a = null;
            a.ThrowIsNull(new AccountOutDto
            {
                OpenID = "1"
            });
            return this.Ok("请求成功");
        }


        [HttpPost("argumentnull")]
        public IActionResult argumentNull()
        {
            var a = 0;
            var b = 0;
            var c = a / b;
            return this.Ok(c);
        }

        [HttpPost("expressisfalse")]
        public IActionResult expressisfalse(int dividend)
        {
            CheckHelper.ThrowExpressIsFalse(() => dividend != 0, 0, "被除数不能是0");
            return this.Ok();
        }

        [HttpPost("IsCountZero")]
        public IActionResult ThrowIsCountZero()
        {
            var list = new List<string>
            {
                "a"
            };

            // list = null;
            list.ThrowIsNull(0, "list 不能为空");

            // list = new List<string>();
            list.ThrowIsCountZero(0, "list 长度不能为0");

            // list = null;
            list = new List<string>();
            list.ThrowIsNullCountZero(0, "list 不能为空或者长度不能为0");
            return this.Ok(list);
        }
    }
}